package com.zsc.edu.testfragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class MyFragment extends Fragment {

    int img;
    String text;

    public MyFragment() {
    }

    public MyFragment(int img, String text) {
        this.img = img;
        this.text = text;
    }




    @Nullable
    @Override
    public View onCreateView(@NonNull  LayoutInflater inflater,
                             @Nullable  ViewGroup container,
                             @Nullable  Bundle savedInstanceState) {

        //return super.onCreateView(inflater, container, savedInstanceState);

        //  根据 fragment 布局的id,  将其 inflate 出来
        View view = inflater.inflate(R.layout.fragment, container, false);

        // 根据 id 找到 ImageView 的实例
        ImageView iv = view.findViewById(R.id.iv_img);
        // 设置图片资源
        iv.setImageResource(this.img);

        // 根据 id 找到 TextView 的实例
        TextView tv = view.findViewById(R.id.tv_text);
        // 设置文本内容
        tv.setText(this.text);

        return view;
    }
}
